home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
315_01
/
ftgraph.c
< prev
next >
Wrap
Text File
|
1990-05-14
|
35KB
|
1,492 lines
/* modified 11/89 by T Clune to allow override of autoscaling on graphs. */
/* This lets the user set two or more graphs to the same scale if he likes. */
/* See readme.txt for details on usage. */
/* modified 10/89 to use MSHERC.COM for Hercules support instead of my */
/* Hercules driver. Microsoft verified that MSHERC.COM can be distributed */
/* with applications without infringing on their rights, 10/89. */
/* Also, changed to accept defaults for all inputs as a mouse support */
/* feature. In addition, mgetch() and mgets() from MENU.C are now used */
/* to automatically determine whether the mouse is being supported for */
/* input, instead of changing the function pointers for input statements */
/* depending on how mouse_flag is initialized. Since the function pointers */
/* have not been removed, this change is essentially meaningless here. */
/* Modified by T Clune */
/* Modified 4/89 by Tom Clune to circumvent some versions of DOS that */
/* do not contain the filespec of the program in ARGV[0]. graph_init() */
/* first tries the argv[0] value, and if that fails, tries the name in */
/* the #define, which is the filename with no path (i.e., requires that */
/* you use the default path for the config file) value before aborting. */
/* Because the name is in FTGRAPH.H, you must edit FTGRAPH.H to use the */
/* name you will be using for the program before compiling. */
/* modified 4/89 by Tom Clune to support CGA, VGA, and EGA graphics */
/* to link the program, use: LINK FTGRAPH,,,FTPLOT MOUSELIB MOUSE GRAPHICS */
/* Note that the library GRAPHICS of MS C v. 5.1 must be invoked */
/* explicitly during linking. Similarly, for the no-mouse version */
/* of ftgraph, link: FTGRAPH,,,FTPLOT NONMOUSE GRAPHICS. */
/* Written 3/89 by T Clune to plot FFT and IFT data. */
/* ftgraph.c uses text-mode (ASCII-format) data files structured as */
/* follows: Line 1 will contain an integer specifying the number of data */
/* points in the data set and two floating point values, the minimum and */
/* maximum value for the y-axis of the graph. */
/* The rest of the file is the floating-point data values, separated by */
/* white-space characters (space, carriage-return/line-feed, or tab). */
/* To compile this program, use Microsoft C, v.5, large memory model. */
/* I compiled it will optimization disabled (as I do for all my programs) */
/* but I have no reason to believe that optimization will cause the */
/* the program to fail. */
/* To run the program, FTGRAPH.CNF must be in the same directory as */
/* FTGRAPH.EXE, and you must have DEVICE=ANSI.SYS in your config.sys file */
/* Copyright (c) 1989, Eye Research Institute. All Rights Reserved. */
#include "mouselib.h"
#include "msc_grph.h"
#include "ansi.h"
#include "fft.h"
#include "hpgl.h"
#include "hpglplot.h"
#include "ftgraph.h"
#include "menu.h"
#include "keys.h"
#include <stdlib.h>
#include <process.h>
#include <graph.h>
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
static void graph_init(), reset_options(), ft(), graph_out(), correlate();
static void write_data(), ft_multiply(), autopower(), crosspower();
static int ft_process(), binary_choice();
static void ft_save(), display_menu(), printout(), peak_extract();
static char *get_prompt();
static double *get_data();
static void filter_main(), ft_filter();
static getsfuncptr get_string;
static intptr pause_func;
static double min_amp, filter_units;
static int ft_coords, ft_pos_neg, ft_precis, mouse_flag;
void main(argc, argv)
int argc;
char *argv[];
{
FILE *f;
static char *options[] =
{
"Quit",
"Reset options",
"Forward transform (file output)",
"Inverse transform (file output)",
"Multiply two data files (file output)",
"Auto-power spectrum (file output)",
"Cross-power spectrum (file output)",
"Correlation from power spectrum data (file output)",
"Filter time-domain real data (file output)",
"Display data file (HPGL, graphics screen, or printer)"
};
/* menu parameters. See menu.c documentation */
int top, left, tab, columns, spacing, entries, auto_label;
int choice; /* menu selection variable */
top=3; /* initialize menu variables */
left=20;
tab=0;
columns=1;
spacing=2;
entries=10;
auto_label= -2;
graph_init(argv[0]);
/* if mouse enabled, set menu variable for mouse operation */
if(mouse_flag==MOUSE_ON)
mouse_flag_toggle(MOUSE_PLUS_KEYBOARD);
reset_menu(0);
for(;;)
{
/* CLS, POSITION, and CHAR_ATTRIBUTE are ANSI.H macros */
CLS;
POSITION(20,1); /* center heading */
CHAR_ATTRIBUTE(UNDERSCORE);
printf("MAIN MENU -- FFT GRAPHING FUNCTIONS\n");
CHAR_ATTRIBUTE(NORMAL);
while(kbhit())
getch();
/* get a menu selection */
choice=menu(top,left,tab,columns,spacing,entries,auto_label,options);
switch(choice) /* see the OPTION strings for meaning of choice */
{
case 0:
CLS;
exit(0);
case 1:
CLS;
reset_options();
reset_menu(choice);
break;
case 2:
CLS;
ft(FORWARD);
reset_menu(choice);
break;
case 3:
CLS;
ft(INVERSE);
reset_menu(choice);
break;
case 4:
CLS;
ft_multiply();
reset_menu(choice);
break;
case 5:
CLS;
autopower();
reset_menu(choice);
break;
case 6:
CLS;
crosspower();
reset_menu(choice);
break;
case 7:
CLS;
correlate();
reset_menu(choice);
break;
case 8:
CLS;
filter_main();
reset_menu(choice);
break;
case 9:
CLS;
display_menu();
reset_menu(choice);
break;
default:
break;
}
}
}
/* autopower() performs an auto power spectrum on the selected data */
static void autopower()
{
static double *x, *y, *minval, *maxval;
static string_struc f;
static int n;
int i;
char c;
int coords;
CLS;
printf("This auto power routine asks only for the real data set.\n");
printf("NOTE WELL: The autopower FT has different units than a normal FT, and is\n");
printf("called variously an auto spectrum, a power spectrum or the power spectral\n");
printf("density of the data set.\n");
printf("NOTICE: Since a power spectrum is defined relative to the area under\n");
printf("the PSD AMPLITUDE graph, this routine produces polar format output,\n");
printf("no matter what coordinate system you are using for FTs.\n");
printf("Phase data for a power spectrum is meaningless, and will not be saved\n");
printf("The inverse FT of this routine's output is called an autocorrelation\n");
printf("and is a measure of the extent to which the data set is self-similar\n");
printf("If you want to inverse-transform the output, you should make sure\n");
printf("that you have positive/negative selected for your transform option.\n");
printf("Because of the way that various flags internal to the program are set,\n");
printf("you should use the CORRELATION menu option instead of INVERSE TRANSFORM\n");
printf("to obtain the correlation IFT.\n");
printf("The IFT (auto-correlation) will have 0 lag in center-screen.\n");
printf("0 lag is perfect correlation (unshifted data correlates exactly to itself)\n\n");
printf("Now, select the data file. Press any key to continue.\n");
(* pause_func)();
coords=ft_coords;
ft_coords=POWER;
do
{
f=get_file();
if(f.error_flag != 0)
{
printf("Do you want to abort this function and return to the main menu (y/N)?\n");
c=binary_choice('N','Y');
if(c=='Y')
{
ft_coords=coords;
return;
}
}
}while(f.error_flag != 0);
x=get_data(f.string,x,&n,minval, maxval);
y=(double *)calloc(n, sizeof(double));
if(y==NULL)
{
printf("Error allocat